<template>
  <!-- 采购清单 -->
  <div>
    <div class="btn-group" v-if="$route.query.status !== '查看'">
      <el-button v-if="acceptanceType == '3'" type="single-number" plain @click="hideDilog = true"
        >选合同物资</el-button
      >
      <el-dropdown type="single-number" plain>
        <el-button class="pl-btn" size="mini" plain>
          批量设置<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="batchSite"
            >批量设置地址</el-dropdown-item
          >
          <el-dropdown-item @click.native="batchManufacturers"
            >批量设置生产厂家</el-dropdown-item
          >
          <el-dropdown-item @click.native="resetNum"
            >批量清零本次验收数量</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>

      <el-button type="single-number" plain @click="handleCopy"
        >复制行</el-button
      >
      <el-button type="single-number" plain @click="handleDelete"
        >删除行</el-button
      >
    </div>
    <!-- 表格-带合计行 -->
    <div
      class="ccui-multifunctional-table-wrapper"
      style="margin:20px 0 70px 0"
    >
      <ux-grid
        max-height="560"
        show-overflow="title"
        ref="plxTable"
        keep-source
        @select-all="handleSelectionChange"
        @select="handleSelectionChange"
        :header-cell-class-name="must"
        :highlightCurrentRow="false"
        :widthResize="true"
        :edit-config="{ trigger: 'click', mode: 'cell' }"
        :summary-method="getSummaries"
        show-summary
      >
        <ux-table-column
          fixed="left"
          type="checkbox"
          width="60"
        ></ux-table-column>
        <ux-table-column title="序号" type="index" width="80" fixed="left" />
        <ux-table-column
          :show-overflow-tooltip="true"
          fixed="left"
          width="140"
          field="materialCode"
          title="设备物资编码"
        >
        </ux-table-column>
        <ux-table-column
          :show-overflow-tooltip="true"
          fixed="left"
          width="300"
          field="materialName"
          title="设备物资名称"
        >
        </ux-table-column>
        <ux-table-column
          width="130"
          :show-overflow-tooltip="true"
          field="material"
          title="设备物资型号"
        >
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          field="materialState"
          width="130"
          title="设备物资说明"
          v-if="$route.query.status === '查看'"
        >
          <template v-slot="scope">
            <span>{{ NumberZero(scope.row.materialState) }}</span>
          </template>
        </ux-table-column>
        <ux-table-column
          v-else
          :show-overflow-tooltip="true"
          field="materialState"
          width="130"
          title="设备物资说明"
          :edit-render="{ autofocus: '.el-input__inner' }"
        >
          <template v-slot:edit="scope">
            <el-input
              :disabled="$route.query.status === '查看'"
              type="text"
              v-model="scope.row.materialState"
            ></el-input>
          </template>
          <template v-slot="scope">
            <span class="my-input-sc span-input">{{ scope.row.materialState }}</span>
          </template>
        </ux-table-column>
        <ux-table-column
          :show-overflow-tooltip="true"
          field="categoryName"
          title="分类名称"
          width="130"
        >
        </ux-table-column>
        <ux-table-column
          :show-overflow-tooltip="true"
          field="measureUnit"
          title="计量单位"
          width="90"
        >
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          width="160"
          field="contractNumber"
          :formatter="numFormatter"
          :title="acceptanceType == '3' ? '合同数量' : '订单数量'"
        >
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          width="160"
          field="contractNumber"
          :formatter="numFormatter"
          title="已验收数量"
        >
        </ux-table-column>

        <ux-table-column
          v-if="
            $route.query.status === '查看' || $route.query.status === '编辑'
          "
          :show-overflow-tooltip="true"
          width="160"
          field="acceptanceCurrentEndNumber"
          :formatter="acceptanceCurrentFormatter"
          title="本次实际验收数量"
        >
        </ux-table-column>
        <ux-table-column
          :show-overflow-tooltip="true"
          field="acceptanceCurrentNumber"
          width="130"
          title="本次验收数量"
          v-if="$route.query.status === '查看'"
        >
          <template v-slot="scope">
            <span>{{ NumberZero(scope.row.acceptanceCurrentNumber) }}</span>
          </template>
        </ux-table-column>
        <ux-table-column
          v-else
          :show-overflow-tooltip="true"
          field="acceptanceCurrentNumber"
          width="130"
          title="本次验收数量"
          :edit-render="{ autofocus: '.el-input__inner' }"
        >
          <template v-slot:edit="scope">
            <el-input
              :disabled="$route.query.status === '查看'"
              type="text"
              @blur="
                bcysNumRules($event, scope.row.bowOutCurrentNumber, scope.row)
              "
              v-model="scope.row.acceptanceCurrentNumber"
            ></el-input>
          </template>
          <template v-slot="scope">
            <span class="my-input-sc span-input">{{
              NumberZero(scope.row.acceptanceCurrentNumber)
            }}</span>
          </template>
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          field="acceptanceDate"
          title="验收日期"
          width="160"
          v-if="$route.query.status === '查看'"
        >
          <template v-slot="scope">
            <span>{{ formatDate(scope.row.acceptanceDate) }}</span>
          </template>
        </ux-table-column>
        <ux-table-column
          v-else
          :show-overflow-tooltip="true"
          width="160"
          field="acceptanceDate"
          title="验收日期"
          :edit-render="{ autofocus: '.el-input__inner' }"
        >
          <template v-slot:edit="scope">
            <el-date-picker
              :disabled="$route.query.status === '查看'"
              v-model="scope.row.acceptanceDate"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </template>
          <template v-slot="scope">
            <span class="my-input-sc span-input">{{
              formatDate(scope.row.acceptanceDate)
            }}</span>
          </template>
        </ux-table-column>
        <ux-table-column
          v-if="$route.query.status === '查看'"
          :show-overflow-tooltip="true"
          width="350"
          field="daohuo"
          title="验收地点"
        >
          <template v-slot="scope">
            <span>{{ scope.row.testdaohuo }}</span>
          </template>
        </ux-table-column>
        <ux-table-column
          v-else
          :show-overflow-tooltip="true"
          width="350"
          field="daohuo"
          title="验收地点"
          :edit-render="{ autofocus: '.el-input__inner' }"
        >
          <template v-slot:edit="scope">
            <el-input
              :disabled="$route.query.status === '查看'"
              readonly
              type="text"
              v-model="scope.row.testdaohuo"
              @focus="daohuoDialog(scope.row)"
            ></el-input>
          </template>
          <template v-slot="scope">
            <span class="my-input-sc span-input">{{
              scope.row.testdaohuo
            }}</span>
          </template>
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          width="250"
          field="manufacturerBrand"
          title="生产厂家/品牌"
          v-if="$route.query.status === '查看'"
        >
          <template v-slot:default="scope">
            <span>{{ scope.row.manufacturerBrand }}</span>
          </template>
        </ux-table-column>
        <ux-table-column
          v-else
          :show-overflow-tooltip="true"
          width="250"
          field="manufacturerBrand"
          title="生产厂家/品牌"
        >
          <template v-slot:default="scope">
            <div style="disple:flex;">
              <el-input
                disabled
                style="width:80%"
                v-model="scope.row.manufacturerBrand"
                type="text"
              />
              <el-button
                :disabled="$route.query.status === '查看'"
                @click="checkBrand(scope.row)"
                type="primary"
                plain
                >选择</el-button
              >
            </div>
          </template>
        </ux-table-column>

        <ux-table-column
          :show-overflow-tooltip="true"
          field="remake"
          width="150"
          title="备注"
          v-if="$route.query.status === '查看'"
        >
          <template v-slot:default="scope">
            <span>{{ scope.row.remake }}</span>
          </template>
        </ux-table-column>
        <ux-table-column
          v-else
          :show-overflow-tooltip="true"
          field="remake"
          width="150"
          title="备注"
          :edit-render="{ autofocus: '.el-input__inner' }"
        >
          <template v-slot:edit="scope">
            <el-input v-model="scope.row.remake" type="text" maxlength="1000" />
          </template>
          <template v-slot="scope">
            <span class="my-input-sc span-input">{{ scope.row.remake }}</span>
          </template>
        </ux-table-column>
      </ux-grid>
    </div>

    <!-- 物料目录 -->
    <material :hideDilog.sync="hideDilog" @materialArr="materialArr" />
    <!-- 地址选择弹框 -->
    <listSettings
      ref="listSettings"
      dialogTitle="验收地点"
      :isSelect="true"
      status="address"
      addressLabel="验收地点"
      @cancesite="cancesite"
      :detail="rowSite"
      @ok="getSite"
    />
    <!-- 单行厂家/品牌选择弹框 -->
    <manufacturers-checked
      :typeList="typeList"
      :matLessList="matLessList"
      @ok="getManufacturers"
      @reset="resetManufacturers"
      ref="manufacturersChecked"
    />
    <!-- 多行厂家/品牌选择弹框 -->
    <manufacturers-checked-all
      :typeList="typeList"
      :matLessList="matLessList"
      @ok="getManufacturersAll"
      @reset="resetManufacturers"
      ref="manufacturersCheckedAll"
    />
  </div>
</template>
<script>
import BigNumber from "bignumber.js";

import manufacturersChecked from "./manufacturers-checked";
import manufacturersCheckedAll from "./manufacturers-checked-all";

import listSettings from "@/basa/components/public/listSettings";
import material from "./material.vue";
// import { getSmpPcConcById } from "../api";
import { generateUUID, formatNumber } from "@/basa/utils";

export default {
  components: {
    material,
    listSettings,
    manufacturersChecked,
    manufacturersCheckedAll
  },
  props: {
    title: {
      type: String,
      default: "标题"
    },
    listData: {
      type: Array,
      default: function() {
        return [];
      }
    },
    acceptanceTypeCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      hideDilog: false,
      tableData: [],
      rowSite: {}, // 当前点击的地址弹框回显
      checkedLine: [], // 被选中数据
      dialogFormVisible: false,
      acceptanceCurrentNumberTotal: 0, // 合计本次验收数量
      timer: "",
      typeList: 0, // 大类
      checkId: "", // 当前项id
      matLessList: [],
      allSet: "",
      allSetSite: "",
      acceptanceType: ''
    };
  },
  watch: {
    listData: {
      handler(n) {
        n.forEach(item => {
          item.uuid = generateUUID();
        });
        this.tableData = n;
        this.$nextTick(() => {
          this.$refs.plxTable.reloadData(this.tableData);
        });
      },
      immediate: true
    },
    tableData: {
      handler(n) {
        n.forEach((item, index) => {
          item.sno = index;
        });
        this.$emit("getInventory", n);
      },
      immediate: true
    },
    acceptanceTypeCode: {
      handler(n) {
        if (n) {
          this.acceptanceType = n;
        }
      }
    }
  },
  activated() {
    if (this.$route.query.status === "新增") {
      this.acceptanceType = this.$route.query.title === '按合同验收' ? '3' : '2';
    }
  },
  deactivated() {
   this.clearTable()
    this.$store.commit("setContractId", null);
    this.$store.commit("setContractCode", null);
  },

  methods: {
    // 清空表格
    clearTable(){
       this.tableData = [];
    this.$refs.plxTable.reloadData([]);
    },
    // 多行获取选中品牌
    getManufacturersAll(data) {
      if (this.checkedLine.length < 1) {
        this.tableData.forEach(item => {
          // 生产厂家/品牌ID
          item.manufacturerBrandId = data[0].id;
          item.manufacturerBrand =
            data[0].manufacturerName + "/" + data[0].brandName;
        });
      } else {
        this.checkedLine.forEach(element => {
          this.tableData.forEach(item => {
            if (element.uuid === item.uuid) {
              // 生产厂家/品牌ID
              item.manufacturerBrandId = data[0].id;
              item.manufacturerBrand =
                data[0].manufacturerName + "/" + data[0].brandName;
            }
          });
        });
      }
    },
    // 单行获取选中品牌
    getManufacturers(data) {
      this.tableData.forEach(item => {
        if (item.uuid === this.checkId) {
          // 生产厂家/品牌ID
          item.manufacturerBrandId = data[0].id;
          item.manufacturerBrand =
            data[0].manufacturerName + "/" + data[0].brandName;
        }
      });
      this.checkId = null;
    },
    // 关闭厂家品牌弹框
    resetManufacturers() {
      this.typeList = 0;
      this.matLessList = [];
    },
    // 批量设置生产厂家
    batchManufacturers() {
      const tableList =
        this.checkedLine.length < 1 ? this.tableData : this.checkedLine;
      const arr = tableList.every(item => {
        let itemCode = item.thirdCategoriesOfCode || item.categoryCode;
        let firstCode =
          tableList[0].thirdCategoriesOfCode || tableList[0].categoryCode;
        return itemCode.substring(0, 2) === firstCode.substring(0, 2);
      });

      if (arr) {
        this.$refs.manufacturersCheckedAll.dialogFormVisibleAll = true;
        this.matLessList = this.getAllIds(tableList);
      } else {
        this.$message.warning("只能批量设置相同类型数据");
      }
    },
    // 获取tableData品牌id交集使用
    getAllIds(list) {
      let arr = [];
      list.forEach(item => {
        arr.push(item.qingdanId);
      });
      let newArr = [...new Set(arr)];
      return newArr;
    },
    // 选择品牌按钮点击事件
    checkBrand(row) {
      console.log(row, "rowyaaaa");
      this.checkId = row.uuid;
      this.matLessList = [row.qingdanId];
      this.$refs.manufacturersChecked.dialogFormVisible = true;
    },

    // 本次验收数量值校验
    bcysNumRules(e, bowOutCurrentNumber, row) {
      if (this.$route.query.status === "编辑") {
        if (
          e.target.value &&
          bowOutCurrentNumber &&
          e.target.value < bowOutCurrentNumber
        ) {
          this.$message.warning("本次验收数量不得小于已退货数量");
        }
      }
      if (isNaN(e.target.value * 1)) {
        row.acceptanceCurrentNumber = "";
      } else {
        if (e.target.value * 1 <= 0) {
          row.acceptanceCurrentNumber = "";
        } else {
          row.acceptanceCurrentNumber = formatNumber(e.target.value, 3);
        }
      }
    },
    // 地址弹框取消按钮
    cancesite() {
      this.allSetSite = "";
    },
    // 地址栏确定按钮
    getSite(val) {
      let arr = [];
      if (this.allSetSite === "批量") {
        if (this.checkedLine.length === 0) {
          this.tableData.forEach(item => {
            // 拼接地址
            item.testdaohuo =
              val.deliveryAreaName +
              val.provinceName +
              (val.cityName || "") +
              (val.countyName || "") +
              (val.deliveryPoints || "");

            // 数据内加入未拼接的的值
            // 所在区域
            item.areaName = val.deliveryAreaName;
            item.areaCode = val.deliveryAreaCode;
            //所在省/国家编码
            item.provinceCode = val.province;
            //所在省名称
            item.provinceName = val.provinceName;
            //所在市/城市编码
            item.cityCode = val.city;
            //所在市/城市名称
            item.cityName = val.cityName;
            //所在县编码
            item.countyCode = val.county;
            //所在县名称
            item.countyName = val.countyName;
            //地点
            item.acceptancePlace = val.deliveryPoints;

            item.deliveryAreaCode = val.deliveryAreaCode;
            item.deliveryAreaName = val.deliveryAreaName;
            item.province = val.province;
            item.city = val.city;
            // arr.push(item);
          });
        } else {
          this.checkedLine.forEach(element => {
            this.tableData.forEach(item => {
              if (element.uuid === item.uuid) {
                // 拼接地址
                item.testdaohuo =
                  val.deliveryAreaName +
                  val.provinceName +
                  (val.cityName || "") +
                  (val.countyName || "") +
                  (val.deliveryPoints || "");

                // 数据内加入未拼接的的值
                // 所在区域
                item.areaName = val.deliveryAreaName;
                item.areaCode = val.deliveryAreaCode;
                //所在省/国家编码
                item.provinceCode = val.province;
                //所在省名称
                item.provinceName = val.provinceName;
                //所在市/城市编码
                item.cityCode = val.city;
                //所在市/城市名称
                item.cityName = val.cityName;
                //所在县编码
                item.countyCode = val.county;
                //所在县名称
                item.countyName = val.countyName;
                //地点
                item.acceptancePlace = val.deliveryPoints;

                item.deliveryAreaCode = val.deliveryAreaCode;
                item.deliveryAreaName = val.deliveryAreaName;
                item.province = val.province;
                item.city = val.city;
              }
              // arr.push(item);
            });
          });
        }
      } else {
        this.tableData.forEach(item => {
          if (item.uuid === this.checkId) {
            // 拼接地址
            item.testdaohuo =
              val.deliveryAreaName +
              val.provinceName +
              (val.cityName || "") +
              (val.countyName || "") +
              (val.deliveryPoints || "");

            // 数据内加入未拼接的的值
            // 所在区域
            item.areaName = val.deliveryAreaName;
            item.areaCode = val.deliveryAreaCode;
            //所在省/国家编码
            item.provinceCode = val.province;
            //所在省名称
            item.provinceName = val.provinceName;
            //所在市/城市编码
            item.cityCode = val.city;
            //所在市/城市名称
            item.cityName = val.cityName;
            //所在县编码
            item.countyCode = val.county;
            //所在县名称
            item.countyName = val.countyName;
            //地点
            item.acceptancePlace = val.deliveryPoints;

            item.deliveryAreaCode = val.deliveryAreaCode;
            item.deliveryAreaName = val.deliveryAreaName;
            item.province = val.province;
            item.city = val.city;
          }
          arr.push(item);
        });
        this.checkId = "";
        this.tableData = arr;
      }
      this.allSetSite = "";
    },
    // 批量设置地址
    batchSite() {
      this.allSetSite = "批量";
      this.rowSite = {};
      this.$refs.listSettings.showDialogVisible = true;
      this.$refs.listSettings.getQryAreaAddress();
    },
    // 到货地址点击事件
    daohuoDialog(row) {
      if (this.$route.query.status === "查看") return;
      this.$refs.listSettings.showDialogVisible = true;
      this.$refs.listSettings.getQryAreaAddress();
      this.checkId = row.uuid;
      this.rowSite = {
        ...row,
        deliveryAreaCode: row.deliveryAreaCode || row.areaCode,
        deliveryAreaName: row.areaName,
        province: row.province,
        city: row.city,
        //详细地址
        deliveryPoints: row.acceptancePlace
      };

      this.$nextTick(() => {
        this.$refs.listSettings.init();
      });
    },
    // 清零处理
    resetNum() {
      if (this.checkedLine.length < 1) {
        this.$message.warning("请选择一项");
        return;
      }
      this.tableData.forEach((pItem, index) => {
        this.checkedLine.forEach(item => {
          item.acceptanceCurrentNumber = "";
          if (pItem.uuid === item.uuid) {
            this.$set(this.tableData[index], "acceptanceCurrentNumber", "");
          }
        });
      });
    },

    // 删除行
    handleDelete() {
      if (this.checkedLine.length < 1) {
        this.$message.warning("请选择一项");
        return;
      }

      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let ids = new Set(this.checkedLine.map(n => n.uuid));
          this.tableData = this.tableData.filter(item => !ids.has(item.uuid));
          this.$nextTick(() => {
            this.checkedLine = [];
            this.$refs.plxTable.reloadData(this.tableData);
          });
        })
        .catch(() => {});
    },

    // 选择到的物料目录
    materialArr(val) {
      val.reverse();
      val.forEach(item => {
        const obj = {
          id: item.id,
          // 物资原合同清单ID
          materialFirstId: item.firstId,
          materialCode: item.materialsCode,
          materialName: item.materialsName,
          materialState: item.matDescribe,
          categoryName: item.thirdCategoriesOfName,
          measureUnit: item.currentMeasuringUnit,
          measureUnitCode: item.currentMeasuringUnitCode,
          contractNumber: item.currentNum,
          qingdanId: item.id,
          // 生产厂家品牌id集合
          smpBrandRelationReqBOS: item.smpBrandRelationReqBOS,
          // 生产厂家/品牌关联id
          manufacturerBrandId: item.id,
          // manufacturerBrand: item.manufacturer,
          manufacturerBrand: "",
          categoryCode: item.thirdCategoriesOfCode,
          // concTotalAcceptanceNumber: item.acceptanceQuantity,
          thirdCategoriesOfCode: item.thirdCategoriesOfCode,
          acceptanceCurrentNumber: item.acceptanceCurrentNumber || "",
          remake: "",
          // 验收地点
          province: item.province,
          provinceCode: item.province,
          provinceName: item.provinceName,
          city: item.city,
          cityCode: item.city,
          cityName: item.cityName,
          county: item.county,
          countyCode: item.county,
          countyName: item.countyName,
          deliveryAreaCode: item.deliveryAreaCode,
          areaCode: item.deliveryAreaCode,
          areaName: item.deliveryAreaName,
          acceptancePlace: item.deliveryPoints,

          // 验收地点
          testdaohuo:
            item.deliveryAreaName +
            item.provinceName +
            item.cityName +
            item.countyName +
            item.deliveryPoints,

          // 验收日期
          acceptanceDate: Date.now(),
          materialId: item.id,
          uuid: generateUUID()
        };
        this.tableData.unshift(obj);
      });
      this.$nextTick(() => {
        this.$refs.plxTable.reloadData(this.tableData);
      });
    },

    // 合计
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              // return prev + curr;
              return new BigNumber(prev).plus(curr);
            } else {
              return prev;
            }
          }, 0);
          if (
            this.$route.query.status === "查看" ||
            this.$route.query.status === "编辑"
          ) {
            if (index == 9 || index == 10 || index == 11) {
              sums[index] = formatNumber(sums[index], 3);
            } else {
              sums[index] = "";
            }
          } else {
            if (index == 9 || index == 10) {
              sums[index] = formatNumber(sums[index], 3);
            } else {
              sums[index] = "";
            }
          }

          // } else {
          //   if (index == 10) {
          //     sums[index] = formatNumber(sums[index], 3);
          //   } else {
          //     sums[index] = "";
          //   }
          // }
        } else {
          sums[index] = "";
        }
      });

      return [sums];
    },

    // 复制行
    handleCopy() {
      if (this.checkedLine.length < 1) {
        this.$message.warning("请选择一项");
        return;
      }
      let index = null;
      this.tableData.forEach((item, i) => {
        if (item.uuid === this.checkedLine[0].uuid) {
          index = i;
        }
      });

      this.checkedLine.forEach(item => {
        item.uuid = generateUUID();
      });

      this.tableData.splice(index + 1, 0, ...this.checkedLine);
      this.checkedLine = [];
      this.$nextTick(() => {
        this.$refs.plxTable.reloadData(this.tableData);
      });
    },
    // 获取选中
    handleSelectionChange(val) {
      let arr = [];
      if (val.length > 0) {
        val.forEach(item => {
          const obj = {
            uuid: item.uuid,
            id: item.id,
            // 订单ID
            materialId: item.materialId,
            // 设备物资编码
            materialCode: item.materialCode,
            //本次发货数量
            deliveryCurrentNumber: item.deliveryCurrentNumber,
            //物资设备名称
            materialName: item.materialName,
            //设备物资说明
            materialState: item.materialState,
            // 分类名称
            categoryName: item.categoryName,
            // 分类名称编码
            categoryCode: item.categoryCode,
            // 计量单位编码
            // currentMeasuringUnitCode: item.currentMeasuringUnitCode,
            // 计量单位
            measureUnit: item.measureUnit,
            // 计量单位编码
            measureUnitCode: item.measureUnitCode,
            // 合同数量
            contractNumber: item.contractNumber,
            // 合同累计数量
            concTotalAcceptanceNumber: item.concTotalAcceptanceNumber,
            // 本次验收数量
            acceptanceCurrentNumber: item.acceptanceCurrentNumber,
            // 生产厂家品牌id集合
            smpBrandRelationReqBOS: item.smpBrandRelationReqBOS,
            qingdanId: item.qingdanId,
            // 生产厂家品牌id
            manufacturerBrandId: item.manufacturerBrandId,
            // 生产厂家/品牌
            manufacturerBrand: item.manufacturerBrand,
            // 物资原合同清单ID
            materialFirstId: item.materialFirstId,
            // 本次验收实际数量
            acceptanceCurrentEndNumber: item.acceptanceCurrentEndNumber,
            // 备注
            remake: item.remake,
            // 验收地点
            provinceName: item.provinceName,
            cityName: item.cityName,
            countyName: item.countyName,
            areaName: item.areaName,
            acceptancePlace: item.acceptancePlace,
            // 验收地址code
            areaCode: item.areaCode,
            provinceCode: item.provinceCode,
            cityCode: item.cityCode,
            countyCode: item.countyCode,
            // 验收日期
            acceptanceDate: item.acceptanceDate,
            // 验收地址
            testdaohuo: item.testdaohuo
          };
          arr.push(obj);
        });
      } else {
        arr = [];
      }
      this.checkedLine = arr;
    },
    // 表格加*号
    must(obj) {
      if (
        obj.column.title === "验收日期" ||
        obj.column.title === "验收地点" ||
        obj.column.title === "本次验收数量" ||
        obj.column.title === "生产厂家/品牌"
      ) {
        return "must";
      }
    },

    // 表单验证定位
    positionFrom() {
      return new Promise((resolve, reject) => {
        if (this.tableData.length < 1) {
          reject({ tabLabel: "物资清单", isFocus: "second" });
          this.$showErrorMessage("请选择合同物资");
          return;
        }
        let testdaohuo = this.tableData.filter(item => {
          // 到货地点必填拦截
          return item.testdaohuo ? item : "";
        });
        if (testdaohuo.length !== this.tableData.length) {
          reject({ tabLabel: "物资清单", isFocus: "second" });
          this.$showErrorMessage("验收地点不能为空");
          return;
        }
        let acceptanceCurrentNumber = this.tableData.filter(item => {
          // 本次验收数量必填拦截
          return item.acceptanceCurrentNumber ? item : "";
        });
        if (acceptanceCurrentNumber.length !== this.tableData.length) {
          reject({ tabLabel: "物资清单", isFocus: "second" });
          this.$showErrorMessage("本次验收数量不能为空");
          return;
        }
        let acceptanceDate = this.tableData.filter(item => {
          // 验收日期必填拦截
          return item.acceptanceDate ? item : "";
        });
        if (acceptanceDate.length !== this.tableData.length) {
          reject({ tabLabel: "物资清单", isFocus: "second" });
          this.$showErrorMessage("验收日期不能为空");
          return;
        }
        let manufacturerBrand = this.tableData.filter(item => {
          // 生产厂家品牌必填拦截
          return item.manufacturerBrand ? item : "";
        });
        if (manufacturerBrand.length !== this.tableData.length) {
          reject({ tabLabel: "物资清单", isFocus: "second" });
          this.$showErrorMessage("生产厂家品牌不能为空");
          return;
        }
        resolve("成功");
      });
    },

    acceptanceCurrentFormatter({ row }) {
      if (row.acceptanceCurrentEndNumber) {
        const num = row.acceptanceCurrentEndNumber * 1;
        return formatNumber(num, 3);
      } else {
        return row.acceptanceCurrentEndNumber;
      }
    },
    // concTotalnumFormatter({ row }) {
    //   if (row.concTotalAcceptanceNumber) {
    //     const num = row.concTotalAcceptanceNumber * 1;
    //     return formatNumber(num, 3);
    //   } else {
    //     return row.concTotalAcceptanceNumber;
    //   }
    // },
    numFormatter({ row }) {
      if (row.contractNumber) {
        const num = row.contractNumber * 1;
        return formatNumber(num, 3);
      } else {
        return row.contractNumber > 0 ? row.contractNumber : "";
      }
    },
    formatDate(date) {
      date = new Date(date); //转换成Data();
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      return y + "-" + m + "-" + d;
    },
    NumberZero(num) {
      return formatNumber(num, 3);
    }
  }
};
</script>
<style lang="scss" scoped>
.ccui-tab-wrapper {
  display: flex;
}
/deep/.el-button + .el-button {
  margin: 10;
}
.btn-group {
  width: 100%;
  text-align: right;
}
/deep/.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}

.el-dropdown {
  margin: 0 10px;
}
/deep/.el-input-group__append .el-button {
  color: #0089ef;
  background: #e6f3fd;
  border-color: #99d0f9;
}

/deep/.el-table__fixed-footer-wrapper tbody td {
  background: #fff;
}
/deep/ .pl-btn {
  padding: 0 20px;
  height: 30px;
  background: #f7f9ff;
  border: 1px solid #0089ef;
  font-weight: 600;
  border-radius: 4px;
  position: relative;
  span {
    font-size: 13px;
    font-weight: 500;
    color: #0089ef;
    display: block;
  }
}

/deep/ .el-table__fixed-header-wrapper {
  th {
    pointer-events: auto;
  }
}

/deep/ .el-table__fixed,
/deep/.el-table__fixed-right {
  pointer-events: none;
  td {
    pointer-events: auto;
  }
}
/deep/ .ccui-multifunctional-table-wrapper .el-table__header-wrapper th {
  border-right: 1px solid #edf2fc;
}
/deep/ .ccui-multifunctional-table-wrapper .el-table td {
  border-right: 1px solid #edf2fc;
}
</style>
